package cn.stylefeng.guns.modular.agv.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.agv.entity.AgvAreaQuota;
import cn.stylefeng.guns.modular.agv.mapper.AgvAreaQuotaMapper;
import cn.stylefeng.guns.modular.agv.model.params.AgvAreaQuotaParam;
import cn.stylefeng.guns.modular.agv.model.result.AgvAreaQuotaResult;
import  cn.stylefeng.guns.modular.agv.service.AgvAreaQuotaService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * agv库区限制 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2025-07-08
 */
@Service
public class AgvAreaQuotaServiceImpl extends ServiceImpl<AgvAreaQuotaMapper, AgvAreaQuota> implements AgvAreaQuotaService {

    @Override
    public void add(AgvAreaQuotaParam param){
        AgvAreaQuota entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(AgvAreaQuotaParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(AgvAreaQuotaParam param){
        AgvAreaQuota oldEntity = getOldEntity(param);
        AgvAreaQuota newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public AgvAreaQuotaResult findBySpec(AgvAreaQuotaParam param){
        return null;
    }

    @Override
    public List<AgvAreaQuotaResult> findListBySpec(AgvAreaQuotaParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(AgvAreaQuotaParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(AgvAreaQuotaParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private AgvAreaQuota getOldEntity(AgvAreaQuotaParam param) {
        return this.getById(getKey(param));
    }

    private AgvAreaQuota getEntity(AgvAreaQuotaParam param) {
        AgvAreaQuota entity = new AgvAreaQuota();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
